<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\access;

use lflow\helper\AssertHelper;

/**
 * 通用过滤类
 *
 * @author Mr.April
 * @since  1.0
 */
class QueryFilter
{
    const ASC = "asc";
    const DESC = "desc";

    //排序字段
    private string $orderBy;

    //排序类型ASC/DESC
    private string $order;

    /*********common parameters***********/
    /**
     * 流程定义id
     */
    private string $processId;

    /**
     * 流程定义版本号
     */
    private int $version;

    /**
     * 流程实例id
     */
    private string $orderId;

    /**
     * 任务id
     */
    private string $taskId;

    /**
     * 创建时间范围
     */
    private string $createTimeStart;
    private string $createTimeEnd;
    private string $operateTime;

    /**
     * 操作人员id
     */
    private string|int $operators;

    /**
     * 名称
     */
    private string $names;

    /**
     * 显示名称
     */
    private string $displayName;

    /**
     * 状态
     */
    private string $state;

    /**
     * 流程类型
     */
    private string $processType;

    /**
     * exclude ids
     */
    private ?string $excludedIds;

    /*********order parameters***********/
    /**
     * 父实例id
     */
    private string $parentId;
    /**
     * 实例编号
     */
    private string $orderNo;

    /*********task parameters***********/
    /**
     * 任务类型
     */
    private int $taskType;

    /**
     * 任务参与类型
     */
    private int $performType;

    /**
     * 是否已设置排序字段,无默认值.
     */
    public function isOrderBySetted(): bool
    {
        return empty($orderBy) && empty($order);
    }

    public function getProcessId(): string|null
    {
        return $this->processId ?? null;
    }

    public function setProcessId(string $processId): QueryFilter
    {
        AssertHelper::notEmpty($processId);
        $this->processId = $processId;
        return $this;
    }

    public function getOrderId(): string|null
    {
        return $this->orderId ?? null;
    }

    public function setOrderId(string $orderId): QueryFilter
    {
        AssertHelper:: notEmpty($orderId);
        $this->orderId = $orderId;
        return $this;
    }

    public function getTaskId(): string|null
    {
        return $this->taskId ?? null;
    }

    public function setTaskId(string $taskId): QueryFilter
    {
        AssertHelper:: notEmpty($taskId);
        $this->taskId = $taskId;
        return $this;
    }

    public function getCreateTimeStart(): string|null
    {
        return $this->createTimeStart ?? null;
    }

    public function setCreateTimeStart(string $createTimeStart): QueryFilter
    {
        AssertHelper:: notEmpty($createTimeStart);
        $this->createTimeStart = $createTimeStart;
        return $this;
    }

    public function getCreateTimeEnd()
    {
        return $this->createTimeEnd ?? null;
    }

    public function setCreateTimeEnd(string $createTimeEnd): QueryFilter
    {
        AssertHelper:: notEmpty($createTimeEnd);
        $this->createTimeEnd = $createTimeEnd;
        return $this;
    }

    public function getOperators(): string|null|int
    {
        return $this->operators ?? null;
    }

    public function setOperators(string $operators): QueryFilter
    {
        AssertHelper:: notNull($operators);
        $this->operators = $operators;
        return $this;
    }

    public function setOperator(string $operator)
    {
        AssertHelper:: notEmpty($operator);
        $this->operators = $operator;
        return $this;
    }

    public function getNames()
    {
        return $this->names ?? null;
    }

    public function setNames(string $names)
    {
        AssertHelper:: notNull($names);
        $this->names = $names;
        return $this;
    }

    public function setName(string $name)
    {
        AssertHelper:: notEmpty($name);
        $this->names = $name;
        return $this;
    }

    public function getDisplayName(): string|null
    {
        return $this->displayName ?? null;
    }

    public function setDisplayName(string $displayName): QueryFilter
    {
        AssertHelper:: notEmpty($displayName);
        $this->displayName = $displayName;
        return $this;
    }

    public function getState(): string|null
    {
        return $this->state ?? null;
    }

    public function setState(int $state): QueryFilter
    {
        AssertHelper:: notNull($state);
        $this->state = (string)$state;
        return $this;
    }

    public function getParentId(): string|null
    {
        return $this->parentId ?? null;
    }

    public function setParentId(string $parentId): QueryFilter
    {
        AssertHelper:: notEmpty($parentId);
        $this->parentId = $parentId;
        return $this;
    }

    public function getOrderNo(): string|null
    {
        return $this->orderNo ?? null;
    }

    public function setOrderNo(string $orderNo)
    {
        AssertHelper:: notEmpty($orderNo);
        $this->orderNo = $orderNo;
        return $this;
    }

    public function getTaskType(): int|null
    {
        return $this->taskType ?? null;
    }

    public function setTaskType(int $taskType): QueryFilter
    {
        AssertHelper:: notNull($taskType);
        $this->taskType = $taskType;
        return $this;
    }

    public function getPerformType(): int|null
    {
        return $this->performType ?? null;
    }

    public function setPerformType(int $performType)
    {
        AssertHelper:: notNull($performType);
        $this->performType = $performType;
        return $this;
    }

    public function getExcludedIds(): string|null
    {
        return $this->excludedIds ?? null;
    }

    public function setExcludedIds(string $excludedIds): QueryFilter
    {
        AssertHelper:: notNull($excludedIds);
        $this->excludedIds = $excludedIds;
        return $this;
    }

    public function getVersion(): int
    {
        return $this->version ?? 0;
    }

    public function setVersion(int $version): QueryFilter
    {
        AssertHelper:: notNull($version);
        $this->version = $version;
        return $this;
    }

    public function getOperateTime(): string|null
    {
        return $this->operateTime ?? null;
    }

    public function setOperateTime(string $operateTime): QueryFilter
    {
        AssertHelper:: notEmpty($operateTime);
        $this->operateTime = $operateTime;
        return $this;
    }

    public function getProcessType(): string|null
    {
        return $this->processType ?? null;
    }

    public function setProcessType(string $processType): QueryFilter
    {
        AssertHelper:: notEmpty($processType);
        $this->processType = $processType;
        return $this;
    }

    public function getOrderBy()
    {
        return $this->orderBy ?? null;
    }

    public function setOrderBy(string $orderBy): void
    {
        $this->orderBy = $orderBy;
    }

    public function orderBy(string $theOrderBy)
    {
        $this->setOrderBy($theOrderBy);
        return $this;
    }

    public function getOrder(): string|null
    {
        return $this->order ?? null;
    }

    public function setOrder(string $theOrder): void
    {
        $this->order = $theOrder;
    }

    public function order(string $theOrder): QueryFilter
    {
        $this->order = $theOrder;
        return $this;
    }

    public function initialized(array $param = []): QueryFilter
    {
        foreach ($param as $key => $value) {
            if (empty($value)) continue;
            $this->{$key} = $value;
        }
        return $this;
    }
}
